<template>
  <div class="station">
    <div class="search">
      <span>
        <el-input
          placeholder="请输入内容"
          v-model="keyword"
          class="input-with-select input-search"
          style="width: 220px"
          @keydown.enter.native="search"
          size="small"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="search()"
          ></el-button>
        </el-input>
        <el-button
          type="success"
          @click="derive()"
          plain="plain"
          class="exit"
          size="small"
          >导出</el-button
        >
      </span>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" align="center" label="员工编号">
      </el-table-column>
      <el-table-column prop="name" align="center" label="员工姓名">
      </el-table-column>
      <el-table-column prop="phone" align="center" label="手机号">
      </el-table-column>
      <el-table-column prop="qqAccount" align="center" label="QQ">
      </el-table-column>
      <el-table-column prop="email" align="center" label="企业微信">
      </el-table-column>
      <el-table-column prop="postName" align="center" label="岗位">
      </el-table-column>
    </el-table>
    <el-col>
      <el-pagination
        style="float: right"
        background
        @size-change="handleSizeChange"
        @current-change="handleChangePage"
        :current-page="tableParams.pn"
        :page-sizes="[5, 10, 15, 20, 30, 40]"
        :page-size="tableParams.ps"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        v-if="total > 0"
      ></el-pagination>
    </el-col>
  </div>
</template>
<script>
import baseTable from "@/components/table/baseTable";
import menuleft from "@/components/menuItem/menuleft.vue";
import { selectUserList, exportEmpInfo } from "@/service/Api.js"; // 接口
// import { exportEmpInfos } from "../../../service/Api";

export default {
  components: { baseTable, menuleft },
  name: "companyMent",
  props: ["menuFlag"],
  data() {
    return {
      tableParams: {
        pn: 1,
        ps: 10,
      },
      keyword: "",
      total: 0,
      tableData: [],
      form: {
        name: "",
      },
      rules: {},
      static: "",
      flag: "",
      id: "",
    };
  },
  created() {
    this.selectUser();
  },
  methods: {
    selectUser() {
      let data = {
        pn: this.tableParams.pn,
        ps: this.tableParams.ps,
        keyword: this.keyword,
      };
      selectUserList(data).then((res) => {
        if (res.code === 0) {
          this.tableData = res.data.records;
          this.total = res.data.total;
        }
      });
    },
    //分页
    handleChangePage(index) {
      this.tableParams.pn = index;
      this.selectUser();
    },
    handleSizeChange(val) {
      this.tableParams.ps = val;
      sessionStorage.setItem("ps", val);
      this.selectUser();
    },
    // 员工-查询
    search() {
      this.tableParams.pn = 1;
      this.selectUser();
    },
    //员工-导出
    derive() {
      let data = {
        pn: this.pn,
        ps: this.ps,
        keyword: this.keyword,
      };
      this.$confirm("此操作将导出数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      }).then(() => {
        exportEmpInfo(data).then((res) => {
          let blob = new Blob([res], {
            // type: "application/vnd.ms-excel;charset=UTF-8",
            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
          });
          let url = window.URL.createObjectURL(blob);
          const link = document.createElement("a"); // 创建a标签
          link.setAttribute("download", new Date().getTime() + ".xlsx");
          document.body.appendChild(link);
          link.download = "员工通讯录";
          link.href = url;
          link.click();
          URL.revokeObjectURL(url); // 释放内存
        });
      });
    },
  },
};
</script>

<style scoped>
.search span {
  display: flex;
  justify-content: space-between;
}

.addPost {
  margin-bottom: 15px;
}

.input-search,
.exit,
.addGroups {
  margin-bottom: 15px;
}
</style>
